package com.bwie.controller;

import com.bwie.entity.Seckill;
import com.bwie.service.SeckillService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/sec")
public class SeckillController {

    @Autowired
    private SeckillService seckillService;


    @RequestMapping("/list")
    public String list(Model model, @RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "2")Integer pageSize){
        PageInfo<Seckill> list = seckillService.list(pageNum,pageSize);
        model.addAttribute("list",list);
        return "sec_list";
    }


    @RequestMapping("/findSeckillById")
    @ResponseBody
    public Seckill findSeckillById(@RequestParam("id") Integer id){
        Seckill seckill = seckillService.findSeckillById(id);
        return  seckill;
    }

    @RequestMapping("/particulars")
    public String particulars(){
        return "sec_particulars";
    }

    @RequestMapping("/findBySeckillByMid")
    @ResponseBody
    public Seckill findBySeckillByMid(@RequestParam(value = "id",required = false) Integer id){
        Seckill seckill =  seckillService.findBySeckillByMid(id);
        return seckill;
    }

    @RequestMapping("/orderAdd")
    public String orderAdd(){
        return "order_add";
    }

}
